home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / serial / callback.001 / callback~ / callback / lib / dbase / toactivefile.c < prev    next >
C/C++ Source or Header  |  1996-07-23  |  2KB  |  61 lines

  1.  
  2. #include "dbase.p"
  3.  
  4. int to_activefile(int dest, FILE *outf, FILE *inf)
  5. {
  6.     char
  7.         *cp,
  8.         buf[300],
  9.         outbuf[300],
  10.     *marker;
  11.     int
  12.         copied = 0,
  13.         len = 0;
  14.  
  15.     while (fgets(buf, 299, inf))                /* read an input line */
  16.     {              
  17.         copied = 1;
  18.         if ((cp = strrchr(buf, '\n')))          /* remove \n at the end */
  19.             *cp = 0;
  20.             
  21.         log(log_on, "->in: '%s'", buf);         /* log what we read */
  22.  
  23.         if (!(marker = strstr(buf, PHONE)))    /* check $PHONE */
  24.         {
  25.             log(log_max, "No $PHONE marker in this line");
  26.             strcpy(outbuf, buf);                /* copy the line as-is */
  27.         }
  28.         else                    /* otherwise, insert phonenr */
  29.         {    
  30.             log(log_max, "Found $PHONE marker in this line");
  31.             len = marker - buf;                 /* length of info to cp */
  32.         strncpy(outbuf, buf, len);          /* copy what's before marker */
  33.         sprintf                             /* append the phonenumber */
  34.         (
  35.         outbuf + len, 
  36.                 "%s%s",            
  37.             get_phone(dest),
  38.             marker + strlen(PHONE)    /* and the trailing info */
  39.         );
  40.         }
  41.  
  42.     log(log_on, "->out: '%s'", outbuf);     /* log what we write */
  43.  
  44.     if 
  45.     (
  46.         (len = fprintf(outf, "%s\n", outbuf))  /* and write the new file */
  47.             !=
  48.             strlen(outbuf) + 1
  49.         )
  50.         {            
  51.             copied = 0;
  52.             break;
  53.         }
  54.     }    
  55.     
  56.     if (!copied)
  57.         return (1);
  58.  
  59.     return (0);
  60. }
  61.